<template>
  <div class="home">
    <el-row id="artList" type="flex" justify="space-around">


      <el-col :span="16" >
        
        <el-row class="art-item" v-for="item in article" :key="item.index">

          <el-card shadow="hover" >
            <h5>
              <router-link :to="{name:'article',params:{id:item.id}}" tag="span" class="art-title"><div class="here" >{{item.title}}</div></router-link>
            </h5>
            <el-row class="art-info d-flex align-items-center justify-content-start">
              <div class="art-time">
                <i class="el-icon-time"></i>
                ：{{item.createtime}}
              </div>
              <div class="d-flex align-items-center">
                <img class="tag" src="../assets/tag.png" />：
                  <el-tag size="mini">{{item.label}}</el-tag>
              </div>
            </el-row>
            <el-row class="art-body">
              <div class="side-img hidden-sm-and-down">
                <img class="art-banner" :src="item.imgcode" />
              </div>
              <div class="side-abstract">
                <div class="art-abstract">{{item.content}}</div>
                <div class="art-more">
                  <router-link :to="{name:'article',params:{id:item.id}}" tag="span">
                    <el-button plain >{{$t('home.readMore')}}</el-button>
                  </router-link>
                  <div class="view">
                    <i class="el-icon-view"></i>
                    {{item.number}}
                  </div>
                </div>
              </div>
            </el-row>
          </el-card>
        
        </el-row>
        

        <div class="block pagination">
          <el-pagination  background  layout="prev, pager, next" @current-change="changge($event)" @next-click="next" :total= "total" :prev-click="last"  :current-page.sync="pageNo" ></el-pagination>
          <!-- <el-pagination
  background
  layout="prev, pager, next"
  total="100"
 > 
</el-pagination> -->
        </div>
      </el-col>
      <el-col :span="6" class="hidden-sm-and-down" id="side">
        <div class="item">
          <tag></tag>
        </div>
        <div class="item">
          <friend></friend>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import friend from "../components/friend.vue";
import tag from "../components/tag.vue";
export default {
  name: "home",
  components: {
    friend,
    tag
  },
  data() {
    return {
      article: [],
      pagenunm:1,
      total:0,
      pageNo:1
    };
  },
  created() {
    var c = this;
    var pagenunm = this.pagenunm;
         
   this.getdata(1);
  },
  methods:{
    changge(val){
      console.log(val)
       this.pageNo = val;
      this.getdata(val);

    },
    next(){
      this.pagenunm++;
this.getdata(this.pagenunm);
    },
    last(){
         if(this.pagenunm == 1){
           return
         }
         this.getdata(--this.pagenunm)
    },
    getdata(pagenunm){

      let c = this;

       this.$http.get("/api/blog/list",{params: { author: "快乐涌动", keyword: "",pagenunm:pagenunm }}).then(res => {
        var x = 0;
       
      console.log(res.data)

       /*  for (let i = 0 ;i< res.data.data.length ; i++) {
			
         c.article[i].name = res.data.data[i].title;
         c.article[i].content = res.data.data[i].content;
         c.article[i].data = res.data.data[i].createtime;
         c.article[i].number = res.data.data[i].number;
         c.article[i].label = res.data.data[i].label;
        
        
        } */
        if(res.data.length == 0){
          return
        }

            c.article = res.data.data.data;
            
           var data = JSON.stringify(res.data.data.number[0])

           

            total = data.split(':', 2)[1].replace('}', '');


          c.total = parseInt(total);
   
      },
      res => {
        console.log(res.status);
      }
    );
    },
    readmore(id,html){


this.$router.push({name:'article',params:{id:id,html:html}})
    }
  }
};
</script>

<style scoped>
#side .item {
  margin-bottom: 30px;
}

.art-item {
  margin-bottom: 30px;
  position: relative;
}

.art-item .star {
  width: 60px;
  height: 60px;
  position: absolute;
  top: 0;
  right: 0;
}

img.tag {
  width: 16px;
  height: 16px;
}

.art-title {
  border-left: 3px solid #f56c6c;
  padding-left: 5px;
  cursor: pointer;
}

.art-title:hover {
  padding-left: 10px;
  color: #409eff;
}

.art-time {
  margin-right: 20px;
}

.art-body {
  display: flex;
  padding: 10px 0;
}

.side-img {
  height: 150px;
  width: 270px;
  overflow: hidden;
  margin-right: 10px;
}

img.art-banner {
  width: 100%;
  height: 100%;
  transition: all 0.6s;
}

img.art-banner:hover {
  transform: scale(1.4);
}

.side-abstract {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.art-abstract {
  flex: 1;
  color: #aaa;
}

.art-more {
  height: 40px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

.art-more .view {
  color: #aaa;
}
h5 {
  font-size: 18px;
}
.pagination {
  background-color: #f9f9f9;
}
.here{
  display: inline-block;
}

.v-enter,
        .v-lerve-to{
            opacity: 0;
            transform: translateY(80px);
        }
        .v-enter-active,
        .v-lerve-active{
            transition: all 1s ease;
        }
        /*添加进场效果*/
        
        .v-move{
            transition: all 2s ease;
        }
        .v-leave-active{
            position: absolute;
        }
</style>